package com.yaozheng.vocationaltraining.adapter;

import net.sf.json.JSONArray;

import com.yaozheng.vocationaltraining.activity.BaseActivity;
import com.yaozheng.vocationaltraining.utils.TypeUtils;
import com.yaozheng.vocationaltraining.view.ItemMyUserInfoDataView;
import com.yaozheng.vocationaltraining.view.ItemMyUserInfoDataView_;
import com.yaozheng.vocationaltraining.view.userinfo.ItemMyUserInfoMedalsDataView;
import com.yaozheng.vocationaltraining.view.userinfo.ItemMyUserInfoMedalsDataView_;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/**
 * 用户资料设备器
 *
 * @author Administrator
 */
public class MyUserInfoDataAdapter extends BaseAdapter {
    JSONArray dataList;

    private BaseActivity baseActivity;

    public MyUserInfoDataAdapter(JSONArray dataList, BaseActivity baseActivity) {
        super();
        this.dataList = dataList;
        this.baseActivity = baseActivity;
    }

    @Override
    public int getCount() {
        return TypeUtils.getJsonArraySize(dataList);
    }

    public JSONArray getDataList() {
        return dataList;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 7) {
            return 1;
        }
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        int itemViewType = getItemViewType(position);
        if (itemViewType == 1) {
            ItemMyUserInfoMedalsDataView itemMyUserInfoDataView;
            if (convertView == null) {
                itemMyUserInfoDataView = ItemMyUserInfoMedalsDataView_
                        .build(baseActivity);
            } else {
                itemMyUserInfoDataView = (ItemMyUserInfoMedalsDataView) convertView;
            }
            itemMyUserInfoDataView.loadData(position,
                    TypeUtils.getJsonObject(dataList, position));
            return itemMyUserInfoDataView;

        } else {
            ItemMyUserInfoDataView itemMyUserInfoDataView;
            if (convertView == null) {
                itemMyUserInfoDataView = ItemMyUserInfoDataView_
                        .build(baseActivity);
            } else {
                itemMyUserInfoDataView = (ItemMyUserInfoDataView) convertView;
            }
            itemMyUserInfoDataView.loadData(position,
                    TypeUtils.getJsonObject(dataList, position));
            return itemMyUserInfoDataView;
        }
    }
}
